<!--
 * @Descripttion: 库存查询列表
 * @version:
 * @Author: cxguo
 * @Date: 2019-08-02 15:03:05
 * @LastEditors: cxguo
 * @LastEditTime: 2020-07-07 16:18:21
 -->
<template>
  <div class="app-container">
    <div>
      <el-card shadow="never" class="oper-btn-card">
        <div class="clearfix">
          <div class="fl">
            <span>业务日期： </span>
            <el-date-picker
              v-model="searchData.rangeTime"
              type="daterange"
              :unlink-panels="true"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
              @change="onDateChange"
            />
            <el-button type="primary" @click="btnSearch">查询</el-button>
            <el-button @click="btnFilter">筛选</el-button>
          </div>
          <div class="fr">
            <el-button @click="btnExportData">导出</el-button>
          </div>
        </div>
      </el-card>
      <el-card shadow="never" class="oper-btn-card">
        <vxe-grid
          ref="table"
          class="grid"
          border
          resizable
          highlight-hover-row
          :loading="tableLoading.stock"
          :edit-config="{trigger: 'click', mode: 'row'}"
          :columns="columnsData"
          :data="tableData.stock"
        />
      </el-card>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        layout="total, sizes,prev, pager, next,jumper"
        :page-size="pageInfo.rows"
        :page-sizes="[20,30,40]"
        :current-page.sync="pageInfo.page"
        :total="pageInfo.total"
        @size-change="onSizeChange"
        @current-change="onCurrentChange"
      />
    </div>
  </div>
</template>
<script>
import { oftenuse } from '@/libs/mixins'
import { getStockList } from '@/api/stock/stock.js'
import Affix from '@/components/Affix'
import { getMoreButton } from '@/components/Table/oper-btns.js'
import Tab from '@/views/components/Tab'
export default {
  name: 'ReportListSale',
  filters: {
  },
  // eslint-disable-next-line vue/no-unused-components
  components: { Affix, Tab },
  mixins: [oftenuse],
  data() {
    return {
      searchData: {},
      stockInfo: {
        oper: 'add',
        data: {}
      },
      dialogVisible: false,
      optionsData: {},
      columnsData: [
        { title: '操作', width: 80,
          slots: {
            default: (params) => {
              const h = this.$createElement
              const moreButtonNode = getMoreButton(h, { props: { type: 'default' },
                on: { click: (row) => { this.btnMore(params) } }})
              const divNode = h('div', {
                attrs: {
                  class: 'table-oper-btns'
                }
              }, [moreButtonNode])
              return [divNode]
            }
          }
        },
        { field: 'code', title: '商品编号', width: 140 },
        { field: 'name', title: '商品名称', width: 200, showOverflow: true },
        { field: 'unitName', title: '基本单位', width: 80 },
        { field: 'canUseQuantity', title: '可用库存', width: 100 },
        { field: 'quantity', title: '当前存货', width: 100 },
        { field: 'originQuantity', title: '期初库存', width: 100 },
        { field: 'waitQuantityIn', title: '待入库量', width: 100 },
        { field: 'waitQuantityOut', title: '待出库量', width: 100 }
      ]
    }
  },
  watch: {
  },
  created() {
    this.getstockList()
  },
  methods: {
    btnExportData() {},
    btnFilter() {},
    btnSearch() {
      this.setBtnLoading('search', true)
      this.getstockList().then(res => {
        this.setBtnLoading('search', false)
      }).catch(err => {
        console.log(err)
        this.setBtnLoading('search', false)
      })
    },
    // api
    getstockList(params = { data: this.searchData, pageInfo: this.pageInfo }) {
      this.setTableLoading('stock', true)
      return new Promise((resolve, reject) => {
        getStockList(params).then(res => {
          this.setTableLoading('stock', false)
          this.setTableData('stock', res.data.records)
          this.pageInfo.total = res.data.total
          resolve(res)
        }).catch(err => {
          this.setTableLoading('stock', false)
          this.$notify.error({ title: '查询异常！', message: err.message })
          reject(err)
        })
      })
    },
    // on
    onSizeChange(val) {
      this.pageInfo.current = 1
      this.pageInfo.size = val
      this.getstockList()
    },
    onCurrentChange(val) {
      this.pageInfo.current = val
      this.getstockList()
    },
    onDateChange(data) {
      if (data) {
        this.$set(this.searchData, 'beginTime', data[0])
        this.$set(this.searchData, 'endTime', data[1])
      }
    }
  }
}
</script>
<style scoped>

</style>
